package tool.analysis.series;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import tool.csv.CSVCompatible;
import tool.csv.FileWriter;

    /**
     * @author jwb09119
     * @date 2013/12/16
     * This class handles analysis of a series of experiments.  By it's nature, this class will be
     * quite specific, will try to mitigate this a bit by having the class depend in an interface.
     */

public class SeriesAnalyser {
    
    private Map<String, ISeriesMember> experiments;
    private FileWriter writer;
    private List<ISeriesAnalysis> analysers;

    
    public SeriesAnalyser (Map<String, ISeriesMember> experiments, FileWriter writer) {

        this.experiments = experiments;
        this.writer = writer;
        analysers = new ArrayList<>();
        analysers.add(new EntityRatioAnalysis(writer));
        analysers.add(new InterfaceUsersCountAnalysis(writer));
        analysers.add(new InterfaceUseOverTimeAnalysis(writer));
        
    }


    /**
     * Pulls data from one or more experiments to perform an series analysis on the data 
     * available.
     */
    public void doSeriesAnalysis () {

        for (ISeriesAnalysis sa : analysers) {
            
            System.out.println("\t- "+sa.getAnalysisTag());
            sa.analyseExperiments(experiments.values());
            
        }
        
        System.out.print("Writing series analysis results to files");
        
        for (ISeriesAnalysis sa : analysers) {
            
            System.out.print(".");
            //TODO - Casting! - sa is ISeriesAnalyser - should this be concrete inheritance?
            writer.dumpObjectToCSVFile( (CSVCompatible) sa, sa.getAnalysisTag());
            
        }
        
        System.out.print("done\n");
    }
    
   
}
